package com.cskaoyan.controller;


import com.cskaoyan.bean.BaseParam;
import com.cskaoyan.bean.User;
import com.cskaoyan.bean.basebean.BaseRespVo;
import com.cskaoyan.bean.zhao_order_bean.BasePageData;
import com.cskaoyan.service.UserService;
import com.cskaoyan.utils.Md5Utils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("admin")
public class UserController {

    @Autowired
    UserService userService;

    @RequiresPermissions("admin:user:list")
    @RequestMapping("user/list")
    public BaseRespVo userList(String username, String mobile, BaseParam param) {
        BasePageData data = userService.queryUser(username, mobile, param);

        return BaseRespVo.ok(data);
    }

    @RequiresPermissions(value = "admin:user:detail")
    @RequestMapping("user/detail")
    public BaseRespVo userDetail(Integer id) {
        User user = userService.queryUserDetail(id);
        return BaseRespVo.ok(user);
    }

    @RequiresPermissions(value = "admin:address:list")
    @RequestMapping("address/list")
    public BaseRespVo addressList(Integer userId, String name, BaseParam param) {
        BasePageData data = userService.queryAddress(userId, name, param);
        return BaseRespVo.ok(data);
    }

    @RequiresPermissions(value = "admin:user:update")
    @RequestMapping("user/update")
    public BaseRespVo userUpdate(@RequestBody User user) throws Exception {
        String password = user.getPassword();
        //Md5加密
        password = Md5Utils.getMd5(password,"password");
        user.setPassword(password);
        userService.updateUser(user);
        return BaseRespVo.ok(user);
    }

    @RequiresPermissions(value = "admin:collect:list")
    @RequestMapping("collect/list")
    public BaseRespVo collectList(Integer userId, Integer valueId, BaseParam param) {
        BasePageData data = userService.queryCollect(userId, valueId, param);
        return BaseRespVo.ok(data);
    }

    @RequiresPermissions(value = "admin:footprint:list")
    @RequestMapping("footprint/list")
    public BaseRespVo footprintList(Integer userId, Integer goodsId, BaseParam param) {
        BasePageData data = userService.queryFootprint(userId, goodsId, param);
        return BaseRespVo.ok(data);
    }

    @RequiresPermissions(value = "admin:history:list")
    @RequestMapping("history/list")
    public BaseRespVo historyList(Integer userId, String keyword, BaseParam param) {
        BasePageData data = userService.queryHistory(userId, keyword, param);
        return BaseRespVo.ok(data);
    }

    @RequiresPermissions(value = "admin:feedback:list")
    @RequestMapping("feedback/list")
    public BaseRespVo feedbackList(Integer id, String username, BaseParam param) {
        BasePageData data = userService.queryFeedback(id, username, param);
        return BaseRespVo.ok(data);
    }

}
